<?php
/**
 * 文件的操作
 * Enter description here ...
 * @author Ju <hipop@126.com>
 *
 */
class Application_Model_DbTable_File extends Application_Model_DbTable_Base
{
    protected $_name = 'files';
	
    /**
	 * 取得文件列表
	 */
	public function getFileListForFlex($pageM = NULL){
		$rows = $this->jqfetchAll($pageM,"`deleted` = 0");
		
		$userM = new Application_Model_DbTable_User();
		$userkv = $userM->getKVnameid();
		
		$data = array();
		if($rows["data"]){
			$data["page"] = $rows["page"];
			$data["total"] = $rows["total"];			
			//$data["data"] = $rows['data'];
			foreach ($rows['data'] as &$row){
				$data["data"][$row["id"]] = $row;	
				$data["data"][$row["id"]]["creat_time"] = date("Y-m-d H:i:s",$row["creat_time"]);				
				$data["data"][$row["id"]]["user_name"] = $userkv[$row['user_id']];
			}
		}
		return $data;
	}
	/**
	 * 批量删除
	 * Enter description here ...
	 * @param array $ids
	 */
	public function delByIds($ids=NULL){
		
		$ids = is_array($ids)?$ids:array($ids);
		foreach ($ids as &$id){
			$id = intval($id);
		}
		$ids = implode(",", $ids);
		$data = array(
			"deleted" => 1
		);
		return $this->update($data, "`id` IN (0{$ids})");
		//return $this->delete("`id` IN (0{$ids})");
	}
	
	/**
	 * 批量禁用
	 * Enter description here ...
	 * @param array $ids
	 */
	public function disabByIds($ids=NULL){
		
		$ids = is_array($ids)?$ids:array($ids);
		foreach ($ids as &$id){
			$id = intval($id);
		}
		$ids = implode(",", $ids);
		$data = array(
			"enabled" => 0
		);
		return $this->update($data, "`id` IN (0{$ids})");
		//return $this->delete("`id` IN (0{$ids})");
	}
	/**
	 * 批量启用
	 * Enter description here ...
	 * @param array $ids
	 */
	public function enabByIds($ids=NULL){
		
		$ids = is_array($ids)?$ids:array($ids);
		foreach ($ids as &$id){
			$id = intval($id);
		}
		$ids = implode(",", $ids);
		$data = array(
			"enabled" => 1
		);
		return $this->update($data, "`id` IN (0{$ids})");
		//return $this->delete("`id` IN (0{$ids})");
	}
}